<!--
 * @description: 编辑工资设置
 * @Author: Coder
 * @Date: 2019-12-18 11:06:05
 * @LastEditors: Please set LastEditors
 -->
<template>
  <div>
    <a-modal v-model="visible" mask destroy-on-close width="800px" :title="data.title" @ok="handleSubmit">
      <a-form :form="form">
        <a-form-item label="名称" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
          <a-input
            v-decorator="[
              'data.name',
              {
                rules: [{ required: true, message: '名字不能为空' }]
              }
            ]"
            :placeholder="addData.name"
            @change="handleName"
          />
        </a-form-item>
        <!-- 备注 -->
        <a-form-item v-if="data.remark" label="备注" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
          <a-textarea v-model="addData.remark" placeholder="写点备注..." :rows="2" />
        </a-form-item>
        <a-form-item label="税前发放" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
          <a-switch v-model="addData.beforeTax" />
        </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>

<script>
export default {
  name: "PayEditor",

  props: {
    payOptions: {
      type: Object,
      default: () => ({
        show: false,
        obj: {}
      })
    }
  },
  data() {
    return {
      form: this.$form.createForm(this, { name: "coordinated" }),
      visible: false,
      data: {},
      addData: {}
    };
  },

  watch: {
    payOptions: {
      handler(val) {
        this.visible = val.show;
        this.data = val.obj;
        this.addData = val.obj.addData;
      }
    }
  },

  methods: {
    /* handleName */
    handleName(val) {},
    /* 显示 */
    showModal() {
      this.visible = true;
    },

    /* 提交 */
    handleSubmit(e) {
      this.form.validateFields((err, values) => {
        if (!err) {
          this.visible = false;
          this.addData.name = values.data.name;
          this.addData.type = 1;
          this.$emit("paySetCb", this.addData);
        }
      });
    },
    /* toggle */
    onChange(checked) {}
  }
};
</script>
